<template>
  <div>
    <div class="blockLeft"><span class="aSpan">{{ptitle}}</span></div>
    <div :class="pline === 1?'blockRightLong':'blockRight'">
      <div v-for="(val,i) in contentList" :key="i">
        <a :onclick="alertFuncStr"
           target="_blank" class="aClass" :href="val.url"><font color="#0000ff">{{val.text}}</font></a>
      </div>
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'

export default {
  name: 'bpmCBlock',
  model: {
    prop: 'pcontent',
    event: 'changed'
  },
  computed: {
    ...mapState(['hsInput', 'bpmcoreI18n']),
    contentList: function () {
      // 组装连接
      let contentListTemp = []
      console.log('imageurl this.pcontent .....', this.pcontent)
      if (this.pcontent && this.pcontent !== null && this.pcontent !== '' && typeof this.pcontent !== 'undefined') {
        let toObj = JSON.parse(this.pcontent)
        console.log('imageurl this.pcontent', toObj)
        if (toObj && toObj.url !== null && toObj.url !== '' && typeof toObj.url !== 'undefined') {
          var _aHrefValue = toObj.url.split(';')
          // 所有url信息输入必须以分号结尾
          for (var i = 0; i < _aHrefValue.length - 1; i++) {
            contentListTemp[i] = {}
            if (_aHrefValue[i].indexOf('&docId') >= 0) {
              // 支持财务IT老版本的编码格式；
              contentListTemp[i].url = _aHrefValue[i]
              contentListTemp[i].text = _aHrefValue[i].split('&docId=')[1]
            } else {
              // 新版本的编码格式
              contentListTemp[i].url = _aHrefValue[i]
              contentListTemp[i].text = _aHrefValue[i].split('%26docId%3D')[1]
            }
          }
        }
      }
      console.log('imageurl content changed .....contentListTemp', contentListTemp)
      return contentListTemp
    },
    alertFuncStr: function () {
      // 内外网访问判断
      let alertFuncStrTemp = ''
      if (this.hsInput && this.hsInput.para) {
        let para = JSON.parse(this.hsInput.para)
        let isIntranet = para ? para.isIntranet: null
        console.log('isIntranet---------->', isIntranet)
        if (isIntranet === '0' || isIntranet === 0) {
          alertFuncStrTemp = 'alert("' + this.bpmcoreI18n.outsideNoVisit + '");return false;'
        }
      }
      return alertFuncStrTemp
    }
  },
  props: {
    // 可能占一整行或行的一半
    pline: {
      type: Number,
      default: 2
    },
    ptitle: {
      type: String,
      default: ' '
    },
    pcontent: {
      type: String,
      default: '{}'
    },
    validateExp: {
      type: Object,
      default () {
        return {}
      }
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .blockLeft {
    background-color: #f4f4f4;
    float: left;
    text-align: center;
    width: 140px;
    min-height: 26px;
    border-left: 1px solid #e3e3e3;
    border-right: 1px solid #e3e3e3;
  }
  .blockRight {
    background-color: #eff3f6;
    float: left;
    padding-left: 8px;
    min-height: 26px;
    width: 340px;
    min-width: 340px;
    text-align: left;
  }
  .blockRightLong {
    background-color: #eff3f6;
    float: left;
    padding-left: 8px;
    min-height: 26px;
    width: 830px;
    min-width: 830px;
    text-align: left;
  }
  .aClass {
    display: block;
    margin-top: 4px;
  }
  .aSpan {
    display: block;
    margin-top: 4px;
  }
</style>
